<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  <input type="text" class="txt">
  <input type="button" class="btn" value="按钮">
  <input type="text" class="result" readonly>
</body>
<script>

  // 选择器
  var txt = document.querySelector(".txt");
  var btn = document.querySelector(".btn");
  var result = document.querySelector(".result");
  // console.log(txt);

  // 绑定事件
  btn.onclick = function(){
    // 获取输入框内容，并转成数值
    var m = txt.value - 0;

    var res = "";
    switch( m ){
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
        res = m + "月共有31天";break;
      case 2:
        res = m + "月共有28天";break;
      case 4:
      case 6:
      case 9:
      case 11:
        res = m + "月共有30天";break;
      default:
        res = "月份错误";
    }

    // 将计算结果放在输入框中
    result.value = res;
  }




</script>
</html>